import Utils from './utils';
const KEY = {
  category: {
    statementExpendList: "@category_statement_expend@",
    statementIncomeList: "@category_statement_income@",
    expendList: "@category_expend_list@",
    incomeList: "@category_income_list@"
  },
  asset: {
    statementAssets: "@asset_statement@",
    list: "@asset_list@"
  },
  alreadyLogin: "@alreadyLogin@",
  bgImageKey: '@user_index_bg@',
  errorKey: '@request_error@',
  loginToken: "@login_token@",
  userInfo: "@user_info@",
  localStatementKey: '@local_statement_cache@'
};

export default {
  key: KEY,

  get: function (key) {
    return wx.getStorageSync(key) || null;
  },

  getUserInfo: function () {
    let userInfo = wx.getStorageSync(KEY.userInfo);
    if (Utils.isNull(userInfo)) {
      return {alreadyLogin: false};
    }
    return userInfo;
  },

  /**
   * 判断用户是否有权限
   * @returns {boolean}
   */
  getUserRoleHasJieLong: function () {
    var userInfo = this.getUserInfo();
    var roles = userInfo.roles;
    if (!Utils.arrayIsNull(roles)) {
      if (roles.includes('jieLongAdmin')) {
        return true
      } else {
        return false
      }
    }
    return false
  },

  set: function (key, value) {
    wx.setStorageSync(key, value);
  },

  clear: function (key) {
    wx.removeStorageSync(key);
  },

  clearAll: function () {
    wx.clearStorage()
  }
};
